package app.fugema.shop.main.home.adapter;


import com.base.common.utils.UIUtils;
import com.base.common.view.adapter.ada.GeneralRecyclerAdapter;
import com.base.common.view.adapter.connector.BaseUniversalItemMultiType;

import android.view.View;

import app.fugema.shop.R;
import app.fugema.shop.main.home.model.LocaCityBean;
import app.fugema.shop.main.home.view.LocationCityActivity;

//extends SingleRecyclerAdapter<StoreBean, ItemHomeStoreItemviewBinding>
public class HomeStoreAdapter extends GeneralRecyclerAdapter
{
    /*
    @Override
    public int getLayoutId()
    {
        return R.layout.item_home_store_itemview;
    }

    @Override
    public void onCreateViewHolder(ItemHomeStoreItemviewBinding binding, BaseViewHolder viewHolder)
    {
        super.onCreateViewHolder(binding, viewHolder);
        binding.rvRecyclerView.setLayoutManager(new MyLinearLayoutManager(viewHolder.itemView.getContext(), 0, false));
        binding.rvRecyclerView.setAdapter(new SingleRecyclerAdapter<StoreBean.ShowProductsBean, ItemOrderShowGoodsViewBinding>()
        {
            @Override
            public int getLayoutId()
            {
                return R.layout.item_order_show_goods_view;
            }

            @Override
            public void onBindViewHolder(ItemOrderShowGoodsViewBinding binding, int position, StoreBean.ShowProductsBean bean)
            {
                super.onBindViewHolder(binding, position, bean);
                binding.setItem( bean );
                binding.executePendingBindings();
                //ImageLoaderUtils.loadImage(binding.givHeadImage, bean);
                if (binding.givHeadImage.getLayoutParams() instanceof ViewGroup.MarginLayoutParams)
                {
                    ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) binding.givHeadImage.getLayoutParams();
                    if (position == 0) {
                        marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_0);
                    } else {
                        marginLayoutParams.leftMargin = DensityUtil.getDimens(R.dimen.dp_f10);
                    }
                    binding.givHeadImage.setLayoutParams(marginLayoutParams);
                }

            }
        });

    }

    @Override
    public void onBindViewHolder(ItemHomeStoreItemviewBinding binding, int position, BaseViewHolder viewHolder, StoreBean bean)
    {
        super.onBindViewHolder(binding, position, viewHolder, bean);

        binding.setItem(bean);
        binding.executePendingBindings();

        if (binding.rvRecyclerView.getAdapter() instanceof BaseRVAdapter)
        {
            BaseRVAdapter rvAdapter = (BaseRVAdapter) binding.rvRecyclerView.getAdapter();
            if (UIUtils.isNotEmpty(bean.getShowProducts()))
            {
                //bean.getShowProducts().subList()

                rvAdapter.setDataList(bean.getShowProducts());
            }
            else
            {
                rvAdapter.clear();
            }
        }
    }

    @Override
    public void onItemClick(View view, BaseRVAdapter adapter, int onclickType, int position, StoreBean bean)
    {
        super.onItemClick(view, adapter, onclickType, position, bean);
        if( UIUtils.isNotEmpty( bean.getShopBranch() ) )
        {
            ShopActivity.start(view.getContext(), bean.getShopBranch().getShopId());
        }
    }
    */
    @Override
    public void initMultiItemType()
    {
        //头部 定位  R.layout.item_gift_detail_footer_view
        putMultiItemType(new BaseUniversalItemMultiType<LocaCityBean>(R.layout.item_home_sstore_title_view)
        {
            @Override
            public int getItemViewType()
            {
                return TYPE_HEAD_ONE;
            }

            @Override
            public void onItemClick(View view, int onclickType, int position, LocaCityBean bean)
            {
                super.onItemClick(view, onclickType, position, bean);
                switch (view.getId())
                {
                    case R.id.tv_city:
                        // 切换城市
                        LocationCityActivity.start(view.getContext(),bean);
                        break;
                    case R.id.ll_search_store:
                        //搜索 店铺
                        UIUtils.showToastSafes("搜索店铺");

                        break;
                }
            }
        });
        //店铺
        putMultiItemType(new HomeNStoreBaseItemMultiType());
    }


}
